﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class nhacungcapDAL:VO.ketnoi
    {
        public List<VO.nhacungcapVO> nhacungcap_xem()
        {
            List<VO.nhacungcapVO> list = new List<VO.nhacungcapVO>();
            using (SqlCommand dbCmd = new SqlCommand("nhacc_xem", GetConnection()))
            {
                VO.nhacungcapVO obj = new VO.nhacungcapVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.nhacungcapIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool nhacungcap_them(VO.nhacungcapVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("nhacc_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@diachi", data.DiaChi));
                    dbCmd.Parameters.Add(new SqlParameter("@mancc", data.MaNcc));
                    dbCmd.Parameters.Add(new SqlParameter("@sdt", data.SDT));
                    dbCmd.Parameters.Add(new SqlParameter("@ten", data.Ten));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {
                
            }

            return true;
        }
        public bool nhacungcap_sua(VO.nhacungcapVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("nhacc_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@diachi", data.DiaChi));
                dbCmd.Parameters.Add(new SqlParameter("@mancc", data.MaNcc));
                dbCmd.Parameters.Add(new SqlParameter("@sdt", data.SDT));
                dbCmd.Parameters.Add(new SqlParameter("@ten", data.Ten));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool nhacungcap_xoa(string mancc)
        {
            using (SqlCommand dbCmd = new SqlCommand("nhacc_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@mahd", mancc));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
}
